package cn.itheima.server_response;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//使用响应对象向浏览器响应中文数据
@WebServlet("/ServletTest5")
public class ServletTest5 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String str = "你好";
        //提到前面来
        response.setContentType("text/html;charset=UTF-8");
        //获取响应字节输出流对象
        ServletOutputStream sos = response.getOutputStream();
        //PrintWriter pw = response.getWriter();
        //pw.print(str);
        sos.write(str.getBytes("UTF-8"));
        sos.close();

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}